package com.dabai.iot.common.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Objects;

/**
 * 设备连接状态枚举
 *
 * @author kev1n
 */
@Getter
@RequiredArgsConstructor
public enum ConnectStatus {

    offline("0", "离线"),
    online("1", "在线"),
    repeat("2", "重新上线"), // 即当前设备在线，又有一个相同序列号的设备上线
    ;

    private final String value;
    private final String desc;

    /**
     * 根据 value 获取对应的枚举
     */
    public static ConnectStatus fromValue(String value) {
        for (ConnectStatus status : values()) {
            if (Objects.equals(status.value, value)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid comparator value: " + value);
    }

}
